package com.wl.wuliu.controller;

import com.wl.wuliu.entity.Customer;
import com.wl.wuliu.result.AjaxResult;
import com.wl.wuliu.service.CustomerService;
import com.wl.wuliu.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @Author: gutaozhen
 * @Date: 2024/5/15
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("/save")
    public AjaxResult save(Customer customer) {
        if (StringUtils.isEmpty(customer.getName())) {
            return AjaxResult.error("姓名不能为空。");
        }
        if (StringUtils.isEmpty(customer.getPhone())) {
            return AjaxResult.error("手机号不能为空。");
        }
        if (StringUtils.isEmpty(customer.getType())) {
            return AjaxResult.error("行业类型不能为空。");
        }
        if (StringUtils.isEmpty(customer.getServer())) {
            return AjaxResult.error("所需服务不能为空。");
        }

        return customerService.saveCustomer(customer);
    }

    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {
        customerService.exportCustomer(response);
    }

}
